#include <gtest/gtest.h>
#include <TxnMemory.h>
#include <TxnMgr.h>
#include <vector>

TEST(TxnMgr_TestCase, Undo)
{
	TxnMgr txnMgr1;

	typedef std::vector<int, txn_allocator<int> > tvector;

	tvector* pv = txn_new<tvector>();

	txnMgr1.StartTxn();
	pv->push_back(1);
	pv->push_back(2);
	txnMgr1.EndTxn();

	ASSERT_TRUE(pv->size() == 2);


	txnMgr1.StartTxn();
	pv->push_back(3);
	pv->push_back(4);
	txnMgr1.EndTxn();

	ASSERT_TRUE(pv->size() == 4);

	txnMgr1.UndoTxn();

	ASSERT_TRUE(pv->size() == 2);

}

TEST(TxnMgr_TestCase, Redo)
{


}

// Mutliple TxnMgr doesn't supported yet
TEST(TxnMgr_TestCase, UndoWithTwoTxnMgr)
{
	TxnMgr txnMgr1, txnMgr2;

	typedef std::vector<int, txn_allocator<int> > tvector;


	// TxnMgr 1
	tvector* pv1 = txn_new<tvector>();

	txnMgr1.StartTxn();
	pv1->push_back(1);
	pv1->push_back(2);
	txnMgr1.EndTxn();

	ASSERT_TRUE(pv1->size() == 2);


	txnMgr1.StartTxn();
	pv1->push_back(3);
	pv1->push_back(4);
	txnMgr1.EndTxn();

	ASSERT_TRUE(pv1->size() == 4);

	// TxnMgr 2
	tvector* pv2 = txn_new<tvector>();

	txnMgr2.StartTxn();
	pv2->push_back(5);
	pv2->push_back(6);
	txnMgr2.EndTxn();

	ASSERT_TRUE(pv2->size() == 2);

	// Undo on TxnMgr 1
	txnMgr1.UndoTxn();

	// check size
	ASSERT_TRUE(pv2->size() == 2);
	ASSERT_TRUE(pv1->size() == 2);

	// check value
	//ASSERT_TRUE(pv2->at(0) == 5);
	//ASSERT_TRUE(pv1->at(0) == 1);

	
}